package com.nuckly.news.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.nuckly.news.common.withArgs
import com.nuckly.news.data.News
import com.nuckly.news.databinding.FragmentNewsBinding
import com.nuckly.news.databinding.FragmentNewsFeedBinding

class NewsFragment : Fragment() {

    companion object {

        private const val ARG_NEWS = "news"

        fun newIntent(news: News) = NewsFragment()
            .withArgs {
                putParcelable(ARG_NEWS, news)
            }

    }

    private var _binding: FragmentNewsBinding? = null
    private val binding get() = _binding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _binding = FragmentNewsBinding.inflate(layoutInflater)
        return binding?.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val news = arguments?.getParcelable(ARG_NEWS) as News?
        binding?.viewModel = news
    }

}